package demo1;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;


public class Log02 {
	@SuppressWarnings("resource")
	public static void main(String[] args) throws IOException, InterruptedException {
		
		
		ArrayList<User> list = new ArrayList<>();
		BufferedReader br= new BufferedReader(new FileReader("user.txt"));
		String line;
		while ((line = br.readLine())!=null){
			String[] arr=line.split("=");
			
			list.add(new User(arr[0],arr[1]));
		}
		br.close();
		int num=1;
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入用户名");
		String name = sc.nextLine();
		while(true){
			Scanner sc1 = new Scanner(System.in);
			System.out.println("请输入密码");
			String passWord = sc1.nextLine();
			int name1=0;
			int count =0;
			for(User s:list){
				if(name.equals(s.getName())){
					name1 = 1;
				}
				if(name.equals(s.getName())&& passWord.equals(s.getPassword())){
					System.out.println("登录成功!");
					count = 1;
				}
			}
			if(name1==0){
					sc = new Scanner(System.in);
					System.out.println("用户名错误");
					System.out.println("请重新输入用户名");
					name = sc.nextLine();
				}
			
			else if(count ==0&&name1==1){
						System.out.println("密码错误!");
					if(num==3){
						System.out.println("请10秒后再输入");
						Thread.sleep(10000);
						System.out.println("等待结束");
					}else if (num==6){
						System.out.println("冻结");
						break;
					}
					num++;
			}else if(count ==0&&name1==0){
				continue;
			}else{
				break;
			}
		}
	}
}
